package cron

import (
	"github.com/robfig/cron/v3"
	"github.com/zhufuyi/sponge/pkg/logger"
	"sync"
)

var (
	singleton *Client
	once      sync.Once
)

type Client struct {
	client *cron.Cron
}

func newClient() *Client {
	logger.Info("定时任务启动成功")
	// 创建定时任务调度器   https://darjun.github.io/2020/06/25/godailylib/cron/
	//http://liuqh.icu/2021/07/18/go/package/27-cron/
	c := cron.New()

	// 启动定时任务调度器
	c.Start()
	return &Client{
		client: c,
	}
}

func GetInstance() *Client {
	once.Do(func() {
		singleton = newClient()
	})
	return singleton
}
